home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 05.zip / BS1 part 5 / PDraw3.0.adf / pdraw_rex.lzh / PlotFunction.pdrx < prev    next >
Text File  |  1992-06-17  |  2KB  |  95 lines

  1. /*
  2. @N
  3.  
  4. This Genie will plot a mathematical function in terms of x and y on the screen
  5. */
  6. signal on error
  7. signal on syntax
  8.  
  9. msg = PDSetup.rexx(2,0)
  10. units = getclip(pds_units)
  11. if msg ~= 1 then exit_msg(msg)
  12.  
  13. cr  = '0a'x
  14. function = getclip(pduser_function)
  15. start = getclip(pduser_fstart)
  16. stop = getclip(pduser_fstop)
  17. npoints = getclip(pduser_fnpoints)
  18. scale = getclip(pduser_fnscale)
  19.  
  20. form = "x0:"start||cr"xn:"stop||cr"n:"npoints||cr"f(x):"function||cr"scale:"scale
  21. form = pdm_getform("Enter function of x", 30, form)
  22. if form= "" then  exit
  23.  
  24. parse var form start '0a'x stop '0a'x numpoints '0a'x function '0a'x scale
  25. if ~(datatype(start, n) & datatype(stop, n) & datatype(numpoints, n)) then
  26.    exit_msg("Invalid Entry")
  27.  
  28. if units = 3 then do
  29.    start = pdm_ConvertUnits(units, 1, start)
  30.    stop = pdm_ConvertUnits(units, 1, stop)
  31. end
  32.  
  33. call setclip(pduser_function, function)
  34. call setclip(pduser_fstart, start)
  35. call setclip(pduser_fstop, stop)
  36. call setclip(pduser_fnpoints, numpoints)
  37. call setclip(pduser_fnscale, scale)
  38.  
  39. call pdm_abortplot()
  40.  
  41. p = pdm_getpagesize()
  42. w = word(p,1)
  43. h = word(p,2)
  44. scale = scale * w / (stop-start)
  45. ox = -start * w / (stop-start)
  46. oy = h / 2
  47.  
  48. /* draw axis */
  49.  
  50. call pdm_setfillpattern(,0)
  51. call pdm_setlinecolor(,"Black")
  52. call pdm_initplot()
  53. if (ox >= 0) & (ox <= w) then do
  54.    call pdm_plotline(ox" 0,"ox" "h", "ox" "oy", 0 "oy", "w" "oy)
  55. end
  56. else do
  57.   call pdm_plotline("0 "oy", "w" "oy)
  58. end
  59. call pdm_endplot()
  60.  
  61. maxy = h/scale
  62. miny = -maxy
  63. call pdm_initplot(ox,oy,scale,-scale,0)
  64. call pdm_setlinecolor(,"Red")
  65. inc = (stop - start) / numpoints
  66.  
  67. do x = start to stop by inc
  68.  
  69.    interpret "y = "function
  70.    y = 1 * y
  71.    if y < miny then y = miny
  72.    if y > maxy then y = maxy
  73.    call pdm_plotsmooth(x" "y)
  74.  
  75. end
  76.  
  77. call pdm_endplot()
  78. exit_msg()
  79.  
  80.  
  81. exit_msg: procedure expose units
  82. do
  83.     parse arg message
  84.  
  85.     if message ~= '' then call pdm_Inform(1,message,)
  86.     call pdm_SetUnits(units)
  87.     call pdm_AutoUpdate(1)
  88.     exit
  89. end
  90.  
  91. error:
  92. syntax:
  93.     exit_msg("Function failed due to error: "errortext(rc))
  94.  
  95.